﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HousingDistribution
{
    class HousingInfoProc
    {
        public void ParseFromMySql(ref List<HousingOccupancyInfo> housingInfo, string fullStr)
        {
            char[] splitChr = { '#' };
            char[] splitChr2 = { '*' };

            //房屋信息字符串数组
            string[] housingInfoStrArr = fullStr.Split(splitChr);

            //单个房屋占用信息字符串数组
            string[] housingOccupancyInfoStrArr = null;

            foreach (string str in housingInfoStrArr)
            {
                try
                {
                    if (str.Length > 0)
                    {
                        housingOccupancyInfoStrArr = str.Split(splitChr2);

                        HousingOccupancyInfo info = new HousingOccupancyInfo();
                        info.id = Convert.ToInt32(housingOccupancyInfoStrArr[0]);
                        info.checkinTime = dateProc.Parse(housingOccupancyInfoStrArr[1]);
                        
                        housingInfo.Add(info);
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
            }
        }

        public void ParseFromMySql(ref List<int> formerHousingId, string fullStr)
        {
            char[] splitChr = { '#' };

            //房屋信息字符串数组
            string[] housingInfoStrArr = fullStr.Split(splitChr);
            
            foreach (string str in housingInfoStrArr)
            {
                try
                {
                    if (str.Length > 0)
                    {
                        formerHousingId.Add(Convert.ToInt32(str));
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
            }
        }

        //判断指定id的房子是否是已经分到的房子之一
        public bool HousingIsCurOccupancy(int id, List<HousingOccupancyInfo> housingInfo)
        {
            foreach (HousingOccupancyInfo info in housingInfo)
            {
                if (info.id == id)
                    return true;
            }

            return false;
        }

        private DateProc dateProc = new DateProc("YYYY-MM-DD");
    }
}
